﻿class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<int> st;
        // function作为map的映射可调⽤对象的类型
        map<string, function<int(int, int)>> opFuncMap = {
        {"+", [](int x, int y) {return x + y; }},
        {"-", [](int x, int y) {return x - y; }},
        {"*", [](int x, int y) {return x * y; }},
        {"/", [](int x, int y) {return x / y; }}
        }; for (auto& str : tokens)
        {
            if (opFuncMap.count(str)) // 操作符
            {
                int right = st.top();
                st.pop();
                int left = st.top();
                st.pop();
                int ret = opFuncMap[str](left, right);
                st.push(ret);
            }
            else
            {
                st.push(stoi(str));
            }
        }
        return st.top();
    }
};